const app= getApp();
const douban = app.globalData.doubanUrl;
import utils from "../../../utils/utils";
const http = utils.http;
const director1 = utils.director;
var handleCasts = utils.handleCasts;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isEmpty:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading({
      title:"加载数据中"
    })
    var id = options.id;
    var url= douban + "subject/"+ id;
    http(url,this.handleData)
  },
  handleData(res){
    var data =res.data;
    var imgUrl= data.images.large;
    var title = data.title;
    var director = director1(data.directors[0]);
    var average = data.rating.average;
    var castsName = handleCasts(data.casts);
    var sum = data.summary;
    this.setData({
      title,director,average,castsName,sum,imgUrl
    })
    wx.setNavigationBarTitle({
      title
    }); //将名字传给每个窗口的标题栏
    wx.hideLoading();
  },
  onPreview(){
    var self = this;
    wx.previewImage({
      urls: [self.data.banner]
    })
  },
  click(){
      wx.chooseImage({
        count: 9,	// 默认为9
        sizeType: ['original', 'compressed'],	// 指定原图或者压缩图
        sourceType: ['album', 'camera'],	// 指定图片来源
        success: function(res) {
          var tempFilePaths = res.tempFilePaths;
          this.setData({
            imgUrl:tempFilePaths,
            isEmpty:false
          })
        }
      })
  }
})